package tests;

import common.Utils;
import constant.Constants;
import org.openqa.selenium.Alert;
import org.openqa.selenium.By;

public class BookListPage extends Utils {
    public BookListPage() {
        // 访问列表页
        driver.get(Constants.LIST_DEFAULT_PATH);
    }

    /**
     * 查看列表页元素
     */
    public void ListByLogin() {
        driver.findElement(By.cssSelector("body > div.bookContainer > div.navbar-justify-between > div > button:nth-child(1)"));
        driver.findElement(By.cssSelector("body > div.bookContainer > table > tbody > tr:nth-child(1)"));
    }

    /**
     * 删除图书信息
     */
    public void DeleteBookInfo() {
        driver.findElement(By.cssSelector("#selectBook")).click();
        driver.findElement(By.cssSelector("body > div.bookContainer > table > tbody > tr:nth-child(1) > td:nth-child(9) > div > a:nth-child(2)")).click();
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        Alert alert = driver.switchTo().alert();
        alert.accept();
    }

    /**
     * 翻页测试
     */
    public void PageTurn() {
        driver.findElement(By.cssSelector("#pageContainer > li:nth-child(5) > a")).click();
        System.out.println(driver.findElement(By.cssSelector("body > div.bookContainer > table > tbody > tr:nth-child(1) > td:nth-child(2)")).getText());
    }

}
